Skip to content

Potential fix for code scanning alert no. 9: Size computation for allocation may overflow#941

Open
arcaven wants to merge 1 commit intodevelopfrom
alert-autofix-9
Open

Potential fix for code scanning alert no. 9: Size computation for allocation may overflow#941
arcaven wants to merge 1 commit intodevelopfrom
alert-autofix-9

Conversation

@arcaven
Copy link
Copy Markdown
Collaborator

@arcaven arcaven commented Apr 19, 2026

Potential fix for https://github.com/ArcavenAE/ThreeDoors/security/code-scanning/9

Add an explicit upper-bound guard in LevenshteinDistance before slice allocations so len(b)+1 cannot overflow and cannot trigger impractically large allocations. The safest no-dependency approach is to cap input lengths using math.MaxInt arithmetic and return a conservative distance when inputs exceed safe bounds.

Best single fix:

  • Edit internal/core/duplicate_detector.go.
  • Import math.
  • In LevenshteinDistance, after empty-string checks and before make, add:
    • if len(b) > math.MaxInt-1 { return len(b) }
    • Optional symmetric safety for a to keep behavior robust in loops: if len(a) > math.MaxInt-1 { return len(a) }
      This preserves existing functionality for normal inputs while preventing overflow at the flagged allocation site(s).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ocation may overflow

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@arcaven arcaven marked this pull request as ready for review April 19, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant